package interator;

import java.util.ArrayList;
import java.util.List;

public class Classroom {

    private List<Student> students = new ArrayList<>();
    private String className;

    Boolean addStudent(Student student){
        students.add(student);
        return true;
    }

    Iterator iterator(){
        return new ClassroomIterator(this);
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    public Integer size(){
        return students.size();
    }

    private class ClassroomIterator implements Iterator<Student> {
        private Classroom classroom;
        private Integer size;
        private Integer index;

        public ClassroomIterator(Classroom classroom) {
            this.classroom = classroom;
            size = classroom.size();
            index = 0;
        }

        @Override
        public boolean hasNext() {
            if(index<size){
                return true;
            }
            return false;
        }

        @Override
        public Student next() {
            Student student = classroom.getStudents().get(index);
            index ++;
            return student;
        }
    }
}
